package com.zhangxun.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zhangxun.domain.Area;
import com.zhangxun.service.AreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api("地址管理接口")
@RestController
@RequestMapping("/admin/area")
public class AreaController {

    @Autowired
    private AreaService areaService;


    @GetMapping("/list")
    @ApiOperation("查询所有地址接口")
    @PreAuthorize("hasAuthority('admin:area:list')")
    public List<Area> listAll(){
        List<Area> list = areaService.list();
        return list;
    }


    @GetMapping("/listByPid")
    @ApiOperation("小程序根据pid查询查寻所有地区接口")
    public ResponseEntity<List<Area>> listByPid(Long pid){
        List<Area> list = areaService.list(new LambdaQueryWrapper<Area>()
                .eq(Area::getParentId, pid));
        return ResponseEntity.ok(list);

    }


}
